home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 1992 August
/
info-mac-1992.iso
/
UNIX
/
Skim Digest.txt
< prev
next >
Wrap
Internet Message Format
|
1992-08-29
|
6KB
Date: Thu, 28 Feb 91 03:00:17 CST
From: 231b3679@fergvax.unl.edu (Mike Gleason)
Subject: [*] skim-digest.c
/* skim-digest.c
* version 1.0, 28 Feb 91, by Mike Gleason, NCEMRSoft.
*
* Purpose: To read only selected articles from the Info-Mac digests.
*
* How to use: Compile this C source code with your favorite C compiler
* on your favorite unix host:
*
* % cc skim-digest.c -O -o skim
*
* Go out and download a digest from sumex-aim.stanford.edu. Run skim:
*
* % skim digest50 digest51 digest49
*
* It should be fairly straightforward from there. When skim finds an
* article in the digest, it will ask you if you want to read it. Type
* <n> <return> to skip the article, or just hit <return> to go ahead
* and read it. Skim's key commands are similar to the "less" and
* "more" text readers; the biggest difference is that Skim only
* recognizes a few keys (in other words, fancy-shmancy stuff like
* grepping through the digest is not supported [yet]). Once you choose
* to read an article, it will pause every screenfull of lines. Hit
* <n> <return> to go to the next article, <q> <return> to quit reading
* the current digest, or just hit <return> to continue reading.
*
* Lastly: I'm curious if anyone else out there besides me will use this;
* If you do, drop me a line at 231b3679@fergvax.unl.edu. I'm putting
* this out into the public domain, so go ahead and submit any revisions
* to sumex.
*/
#define NO_HOT_KEYS
#define SCREEN_HEIGHT 24
#define AT_NEW 1
#define QUIT -1
#define NEXT 0
#define NOT_AT_NEW 0
#define CLEARSCREEN printf("\033[2J \033[H") /* Clear screen. */
#ifdef THINK_C
# define NO_ANSI
# include "stdio.h"
#else
# include <stdio.h>
/* # define NO_ANSI */
/* Uncomment the preceding line if your terminal doesn't like
ANSI screen control characters. */
#endif
int ReadDigest();
int ReadArticle();
char Response();
int StrnEqual();
int main(argc, argv)
int argc;
char **argv;
{
char digestName[80];
short i;
if (argc < 2)
{
printf(" digest to read: ");
fgets(digestName, sizeof (digestName), stdin);
*(digestName + strlen(digestName) - 1) = '\0';
if (digestName)
ReadDigest(digestName);
}
else
{
for (i=1; i<argc; i++)
ReadDigest(argv[i]);
}
#ifdef NO_ANSI
printf("\n(End)\n\n");
#else
printf("\n\033[1m(End)\033[0m\n\n");
#endif
}
int ReadDigest(digestName)
char *digestName;
{
FILE *in;
char lyne[128], dateStr[128];
short articleNum = 0, atNextArticle = NOT_AT_NEW;
if (!(in = fopen(digestName, "r")))
{
fprintf(stderr, "skim-digest: \"%s\" could not be opened.\n",
digestName);
return (0);
}
#ifdef NO_ANSI
printf("Digest: %s:\n\n", digestName);
#else
CLEARSCREEN;
printf("\033[7mDigest: \"%s\"\033[0m \n\n", digestName);
#endif
while (1)
{ /* Go through the digest line by line, looking for "Date:" */
if (atNextArticle != AT_NEW)
{
if (!fgets(lyne, sizeof(lyne), in))
break;
if (!StrnEqual(lyne, "Date:", 5))
continue;
strcpy(dateStr, lyne);
}
articleNum++;
atNextArticle = NOT_AT_NEW;
#ifdef NO_ANSI
printf("Article #%d:\n%s", articleNum, dateStr);
#else
if (articleNum > 1) CLEARSCREEN;
printf("\033[1mArticle #%d\033[0m:\n%s", articleNum, dateStr);
#endif
while (fgets(lyne, sizeof(lyne), in))
{
if (strlen(lyne) < 5)
break;
fputs(lyne, stdout);
/* Write all the header lines. */
}
if (!lyne)
{
fclose(in);
return (0); /* unexpected eof */
}
*lyne = Response("\nRead this post? ");
switch (*lyne)
{
case 'n': case 'N': break;
case 'q': case 'Q': return (1); break;
default:
{
if ((atNextArticle = ReadArticle(in, dateStr)) < 0)
{
fclose(in);
return (1);
}
}
}
}
fclose(in);
return (1);
} /* ReadDigest */
int ReadArticle(in, dateStr)
FILE *in;
char *dateStr;
{
char lyne[128];
register short i;
while(1)
{
#ifndef NO_ANSI
CLEARSCREEN;
#endif
for (i=0; i<SCREEN_HEIGHT-1; i++)
{
if (!fgets(lyne, sizeof(lyne), in))
return (QUIT); /* unexpected eof */
if (StrnEqual(lyne, "Date:", 5))
{
strcpy(dateStr, lyne);
#ifndef NO_ANSI
*lyne = Response("(Hit Return)");
#endif
return (AT_NEW); /* end of article, at beginning of next. */
}
fputs(lyne, stdout);
}
*lyne = Response(":");
switch (*lyne)
{
case 'n': case 'N': return (NEXT); /* screw this article... */
case 'q': case 'Q': return (QUIT); break;
}
}
} /* ReadArticle */
char Response(prompt)
char *prompt;
{
#if defined(MAC) || defined(NO_HOT_KEYS)
char lyne[128];
#endif
#ifndef NO_ANSI
printf("\033[7m%s\033[0m", prompt);
#else
printf("%s", prompt);
#endif
#if defined(MAC) || defined(NO_HOT_KEYS)
fgets(lyne, sizeof(lyne), stdin);
return (*lyne);
#else
return (fgetc(stdin));
#endif
} /* Response */
int StrnEqual(a, b, n)
char *a, *b;
int n;
{
register char *s, *t;
register int i;
s = a; t = b;
for (i=0; i<n; i++)
{
if (*s != *t) return (0);
if (*s == '\0' || *t == '\0') return (1);
s++; t++;
}
return (1);
} /* StrnEqual */
/* eof */